package lomasky.xui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.TypedValue;


public class ImageButton extends android.support.v7.widget.AppCompatTextView {
    String android_namespace = "http://schemas.android.com/apk/res/android";
    private final float DIMEN_1_DP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics());
    private final float DIMEN_72_DP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 72, getResources().getDisplayMetrics());
    private final float DIMEN_8_DP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
    private final float DIMEN_16_DP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics());
    private final float DIMEN_12_SP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics());
    private final long DURATION_SHORT = getResources().getInteger(android.R.integer.config_shortAnimTime);

    private final int COLOR_MATERIAL_RED_500 = 0xfff44336;
    private final int COLOR_HINT;

    // Paddings
    private float basePaddingLeft;
    private float basePaddingTop;
    private float basePaddingRight;
    private float basePaddingBottom;



    private Drawable topIcon;


    public ImageButton(Context context) {
        this(context, null);
    }

    public ImageButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        COLOR_HINT = getCurrentHintTextColor();
        init(context, attrs);
    }

    public ImageButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        COLOR_HINT = getCurrentHintTextColor();
        init(context, attrs);
    }


    private void init(Context context, AttributeSet attrs) {
        // Override API padding
        basePaddingLeft = DIMEN_8_DP;
        basePaddingTop = DIMEN_16_DP;
        basePaddingRight = DIMEN_8_DP;
        basePaddingBottom = DIMEN_16_DP;

        // Remove text top/bottom padding)
        setIncludeFontPadding(false);

        setMinWidth((int) DIMEN_72_DP);
        setMinHeight((int) DIMEN_72_DP);



        // Remove API background
        setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.img_bt_bg));

        int topIcon_res = attrs.getAttributeResourceValue(android_namespace, "drawableTop", 0);

        if (topIcon_res != 0) {
            topIcon = getCompoundDrawables()[1]; // 获取drawableRight
            topIcon = ContextCompat.getDrawable(context, topIcon_res);
            topIcon.setBounds(0, topIcon.getIntrinsicWidth(), 0, topIcon.getIntrinsicHeight());
        }




    }




    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);


    }


}